package cn.niit.pm.controller;

import cn.niit.pm.entity.Declare;
import cn.niit.pm.service.impl.DeclareServiceImpl;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 公告管理
 * @author majiarui
 */
@Slf4j
@Api("公告管理")
@Controller
public class DeclareController {


    @Resource
    private DeclareServiceImpl service;

    @GetMapping("/declare")
    public String declare(Declare declare,
                          @RequestParam(value = "pageSize", defaultValue = "0") int pageSize,
                          @RequestParam(value = "pageNumber", defaultValue = "10") int pageNumber, Model model){
        PageInfo info = service.select(declare, pageSize, pageNumber);
        model.addAttribute("pageInfo", info);
        return "declare_infor/declare";
    }

    @PostMapping("/declare/insert")
    @ResponseBody
    public void insert(Declare declare) {
        service.insert(declare);
    }
    @PostMapping("/declare/update")
    @ResponseBody
    public void update(Declare declare) {
        service.update(declare);
    }
    @GetMapping("/declare/delete/{id}")
    @ResponseBody
    public void delete(@PathVariable("id") Integer id) {
        service.delete(id);
    }

    @GetMapping("/declare/selectById/{id}")
    @ResponseBody
    public Declare selectById(@PathVariable("id") Long id) {
        return service.selectById(id);
    }


    /* *//**
     * 跳转页面
     * @return
     *//*
    @GetMapping("/declare")
    public String declare(){
        return "declare_infor/declare";
    }

    @Autowired
    private DeclareService declareService;

    *//**
     * 招聘计划首页，用于显示公告页面
     * @return
     *//*
    @GetMapping("/declareplan")
    public String declareplan(Model model, Declare declare){
        List<Declare> declareList = declareService.selectListByDeclare(declare);
        model.addAttribute("declareList", declareList);
        return "declare_infor/declare";
    }

    *//**
     *进入 添加/修改 公告页面
     * @param model
     * @param title
     * @return
     *//*
    @GetMapping("/{id}")
    public String saveDeclarePlan(Model model, String title){
        System.out.println(title);
        Declare declare = null;
        if(null != title ){
            declare = declareService.selectByTitle(title);
        }else{
            declare = new Declare();
        }
        model.addAttribute("declare", declare);
        return "declare_infor/declareplan";
    }

    *//**
     *添加合同信息点击“确认保存”按钮后的请求方法
     * @param declare
     * @return
     *//*
//    @PostMapping("/declareplan")
//    public String addDeclarePlan(Declare declare, Model model, User user, HttpServletRequest request){
//        declare.info("待添加的合同信息：{}" + declare);
//        declare.setCreateUserId(5L);
//        declare.setCreateUserName("zhangsan");
//        System.out.println("获取要添加的合同信息：" + declare);
//        int rows = declareService.add(declare);
//        System.out.println("rows" + rows);
//        return "declare_infor/declareplan";
//    }

    *//**
     * 删除合同信息
     * @param title
     * @return
     *//*
    @ResponseBody
    @DeleteMapping("/{id}")
    public String delete(String title){
        System.out.println(title);
        int rows = 0;
        if (null != title ){
            rows = declareService.deleteByDeclare(title);
            if (rows > 0){
                return "true";
            }
        }
        return "false";
    }*/
}
